﻿using CaterModel;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CaterDal
{
    public partial class MemberTypeInfoDal
    {
        public List<MemberTypeInfo> GetList()
        {
            string sql = "select * from MemberTypeInfo where MIsdelete=0";
            DataTable dt = SqliteHelper.GetDataTable(sql);

            List<MemberTypeInfo> list = new List<MemberTypeInfo>();
            foreach (DataRow row in dt.Rows)
            {
                list.Add(new MemberTypeInfo()
                {
                    MId = Convert.ToInt32(row["mid"]),
                    MTitle = row["MTitle"].ToString(),
                    MDiscount =Convert.ToDecimal(row["MDiscount"].ToString()),
                    MIsDelete = Convert.ToBoolean(row["MIsDelete"])
                });
            }

            return list;
        }

        public int Insert(MemberTypeInfo mti)
        {
            string sql = "insert into MemberTypeInfo (MTitle,MDiscount,misdelete) values(@MTitle,@MDiscount,0)";
            SQLiteParameter[] ps = {
                new SQLiteParameter("@MTitle",mti.MTitle),
                 new SQLiteParameter("@MDiscount",mti.MDiscount)
            };

            return SqliteHelper.ExecuteNonQuery(sql, ps);
        }

        public int Update(MemberTypeInfo mti)
        {

            List<SQLiteParameter> listPs = new List<SQLiteParameter>();
            string sql = "update MemberTypeInfo set mtitle=@mtitle";
            sql += ",mdiscount=@mdiscount,misdelete=@misdelete where  mid=@mid";

            listPs.Add(new SQLiteParameter("@mtitle", mti.MTitle));
            listPs.Add(new SQLiteParameter("@mdiscount", mti.MDiscount));
            listPs.Add(new SQLiteParameter("@mid", mti.MId));
            listPs.Add(new SQLiteParameter("@misdelete", mti.MIsDelete));

            return SqliteHelper.ExecuteNonQuery(sql, listPs.ToArray());

        }
    }
}
